<?php
include_once 'module/controls.php';
$c = new controls();
?>
<div id="content">
    <div class="content_block">
        <h2 class="jquery_tab_title"><?php echo $phrase["manager_lienket"] ?></h2>
        <form method="post" action="<?= $url["home"] ?>/menu/lienket-process" enctype="multipart/form-data">
            <p>
                <?php echo $c->get_label($phrase["lienket_name"]) ?>
                <?php echo $c->get_text("lienket_name") ?>
                <span id="errorName" style="display: none">Tên Website không được để trống.</span>
            </p>

            <p>
                <?php echo $c->get_label($phrase["lienket_link"]) ?>
                <?php echo $c->get_text("lienket_link") ?>
                <span id="errorLink" style="display: none">Link không được để trống hoặc Định dạng Link sai.</span>
            </p>
            
            <p>
                <?php echo $c->get_button("accept", $phrase["accept"]) ?>
            </p>
        </form>
    </div>
</div>
<script>
    $('#accept').click(function(){
        var linkReg = /^([\w-\.]+([\w-]+\.)+[\w-]{2,4})?$/;
        var link = $('#lienket_link').val();
        var name = $('#lienket_name').val();
        if(name == ""){
            $('#errorName').show();
            $('#errorLink').hide();
            return false;
        }
        if(link == ""){
            $('#errorLink').show();
            $('#errorName').hide();
            return false;
        }
        if(!linkReg.test(link)){
            $('#errorLink').show();
            $('#errorName').hide();
            return false;
        }
    });
</script>